// 管理用户数据

import { defineStore } from 'pinia'
import { ref } from 'vue'

export const userStore = defineStore(
  'user',
  () => {
    const isDark = ref<boolean>(false)
    // 定义管理用户的数据state
    const userInfo = ref({
      studentId: '',
      stuName: '',
      intvId: undefined,
      examId: undefined
    })
    const defaultUrl = ref()
    // 清除用户数据
    const clearUserInfo = () => {
      userInfo.value = {
        studentId: '',
        stuName: '',
        intvId: undefined,
        examId: undefined
      }
    }

    // 以对象格式将state与action return
    return {
      userInfo,
      defaultUrl,
      clearUserInfo,
      isDark
    }
  },
  {
    persist: true
  }
)
